//
//  XVBaseTabbarController.m
//  DWCustomTabBarDemo
//
//  Created by  刘尚威 on 2017/3/3.
//  Copyright © 2017年 damonwong. All rights reserved.
//

#import "XLTabBarController.h"

#import "Lothar+Current.h"
#import "Lothar+History.h"
#import "Lothar+Mine.h"
#import "XLNavigationController.h"
#import "XLTabBar.h"
@interface XLTabBarController ()<XLTabBarViewDelegate>

@end

@implementation XLTabBarController

-(void)viewDidLoad{
    
    [super viewDidLoad];
    // 利用 KVC 来使用自定义的tabBar；
    XLTabBar *tabBar = [[XLTabBar alloc] init];
    tabBar.tabBarView.delegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
    
    // 设置子控制器
    [self addAllChildViewController];
    
    //去除 TabBar 自带的顶部阴影
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

}

#pragma mark - Private Methods

// 添加子控制器
- (void)addAllChildViewController
{
//    RootViewController *homeVC = [[RootViewController alloc] init];
//    
//    homeVC.view.backgroundColor = [UIColor redColor];
//    [self addChildViewController:homeVC title:@"会诊" navControllerClass:[XLNavigationController class]];
//    
//    UIViewController *activityVC = [[UIViewController alloc] init];
//    activityVC.view.backgroundColor = [UIColor yellowColor];
//    [self addChildViewController:activityVC title:@"历史会诊" navControllerClass:[XLNavigationController class]];
//    
//    UIViewController *findVC = [[UIViewController alloc] init];
//    findVC.view.backgroundColor = [UIColor blueColor];
//    [self addChildViewController:findVC title:@"我的" navControllerClass:[XLNavigationController class]];
    UIViewController *currentVC = [[Lothar shared] current_aViewController];
    [self addChildViewController:currentVC title:@"会诊" navControllerClass:[XLNavigationController class]];
    
    UIViewController *historyVC = [[Lothar shared]history_aViewController];
    [self addChildViewController:historyVC title:@"历史会诊" navControllerClass:[XLNavigationController class]];
    
    UIViewController *mineVC = [[Lothar shared]mine_aViewController];
    [self addChildViewController:mineVC title:@"我的" navControllerClass:[XLNavigationController class]];
}
 
// 添加某个childViewController
- (void)addChildViewController:(UIViewController *)childVc title:(NSString *)title navControllerClass:(Class)navControllerClass
{
    //给控制器 包装 一个导航控制器
    id nav = nil;
    if (navControllerClass == nil) {
        nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    } else {
        nav = [[navControllerClass alloc] initWithRootViewController:childVc];
    }
//    childVc.title = title;
    childVc.navigationItem.title = title;
    //添加为子控制器
    [self addChildViewController:nav];
}

////隐藏tabbar
//-(void)setHidesBottomBarWhenPushed:(BOOL)hidesBottomBarWhenPushed{
//    
//    self.tabBar.hidden = hidesBottomBarWhenPushed;
//    
//}

#pragma mark - XLTabBarViewDelegate
- (void)xlTabBarView:(XLTabBarView *)view didSelectItemAtIndex:(NSInteger)index {
    self.selectedIndex = index;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
